package com.shao.im.webSocket.handler;

import com.shao.im.entity.Message;
import com.shao.im.webSocket.base.BaseChannelInHandler;
import com.shao.im.webSocket.utils.ChannelManager;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.stereotype.Component;

/**
 * 处理用户端的注册
 */
@Component
@ChannelHandler.Sharable
public class RegisterChannelHandler extends BaseChannelInHandler {
    @Override
    protected int action() {
        return 100;
    }

    @Override
    protected void handler(ChannelHandlerContext ctx, Message message) {
        // 处理注册的逻辑
        Integer from = message.getFrom();
        Channel channel = ctx.channel();
        // 存储登录的用户
        ChannelManager.set(from, channel);
    }
}
